package com.shaoshaohuo.app.ui;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.BaseEntity;
import com.shaoshaohuo.app.net.ShopHttpConfig;
import com.shaoshaohuo.app.utils.Okhttputils;
import com.shaoshaohuo.app.utils.im.IMFactory;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Response;

public class WaitCheckActivity extends AppCompatActivity implements View.OnClickListener {
    private Button wait_check_btn;
    /**
     * tobar
     */
    private ImageView order_tobar_back;
    private TextView order_tobar_enter;
    private ImageView order_tobar_right;
    private LinearLayout order_layout_topbar_left;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wait_check);
        initView();

    }

    private void initView() {
        /**
         * tobar
         * */
        order_tobar_back = (ImageView) findViewById(R.id.imageview_topbar_left_backImage);
        order_tobar_back.setVisibility(View.VISIBLE);
        order_tobar_back.setImageResource(R.mipmap.return_key);
        order_tobar_enter = (TextView) findViewById(R.id.toolbar_topname);
        order_tobar_enter.setText("商家入驻");
        order_tobar_right = (ImageView) findViewById(R.id.imageview_message);
        order_tobar_right.setImageResource(R.mipmap.shenhe_kefu);
        order_tobar_right.setVisibility(View.VISIBLE);
        order_layout_topbar_left = (LinearLayout) findViewById(R.id.layout_topbar_left);
        order_layout_topbar_left.setVisibility(View.VISIBLE);
        order_layout_topbar_left.setOnClickListener(this);
        order_tobar_right.setOnClickListener(this);

        wait_check_btn = (Button) findViewById(R.id.wait_check_btn);
        wait_check_btn.setOnClickListener(this);
        order_tobar_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(ShopHttpConfig.phone());
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.imageview_message:
                IMFactory.openChatServiceContact(this);
                break;
            case R.id.layout_topbar_left:
                finish();
                break;
            case R.id.wait_check_btn:
                ShopHttpConfig.cancleFarmDecide(getApplicationContext(), new Okhttputils.OkutListener() {
                    @Override
                    public void error(Call call, IOException e) {

                    }

                    @Override
                    public void error(Call call, int code) {

                    }

                    @Override
                    public void suseff(Call call, Response response, Object o) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(getApplicationContext(), "取消成功", Toast.LENGTH_SHORT).show();
                                finish();

                            }
                        });
                    }
                }, BaseEntity.class);
                break;
        }
    }
}
